package com.fit.pages;



import java.util.LinkedList;

import com.fit.beans.JewelryBean;
import com.fit.interfaces.*;


import com.fit.service.Jewelrys;


import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.annotations.SetupRender;
import org.apache.tapestry5.ioc.annotations.Inject;


public class EntryJewelry {

	@Property
	@Persist
	private Jewelry jewelry;

	@Inject
	private Jewelrys jewelrys;
	
	@SetupRender
	public void createObject() {
		jewelry = new JewelryBean();
		jewelry.setBuy(new LinkedList<Buy>());
	}

	void onSuccess() {
		jewelrys.save(jewelry);
	}
	
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}
//	private String jewelryName = "Unesite naziv nakita";
//	private String jewelryProducer = "Unesite naziv proizvodjaca";
//	private String jewelryShortDescription = "Unesite kratak opis";
	
//	@InjectPage
//	private ViewJewelry viewJewelryPage;
//	@InjectPage
//	private Error errorPage;
	
	
//	@OnEvent(value = "submit", component = "jewelryInputForm")
//	Object onFromSubmit(){
//		Jewelry jewelryBean = new JewelryBean();
//		jewelryBean.setBuy(new LinkedList<Buy>());
//		jewelryBean.setJewelryName(jewelryName);
//		jewelryBean.setProducer(jewelryProducer);
//		jewelryBean.setShortDescription(jewelryShortDescription);
//		if(jewelryBean.getJewelryName() == null || jewelryBean.getProducer() == null){
//			errorPage.setError("Nije moguce dodati nakit ukoliko se ne unese naziv ili proizvodjac");
//		return errorPage;
//		}
//		viewJewelryPage.setSingleJewelry(jewelryBean);
//		return viewJewelryPage;
//		}
//
//
//	public String getJewelryName() {
//		return jewelryName;
//	}


//	public void setJewelryName(String jewelryName) {
//		this.jewelryName = jewelryName;
//	}
//
//
//	public String getJewelryProducer() {
//		return jewelryProducer;
//	}
//
//
//	public void setJewelryProducer(String jewelryProducer) {
//		this.jewelryProducer = jewelryProducer;
//	}


//	public String getJewelryShortDescription() {
//		return jewelryShortDescription;
//	}
//
//
//	public void setJewelryShortDescription(String jewelryShortDescription) {
//		this.jewelryShortDescription = jewelryShortDescription;
//	}
	
}
